import { useMemo } from "react"
import { CompressTask } from "@renderer/services/ipc/ipc.constant"
import $helper from "@renderer/services/helper.service"

type IProps = {
  task: CompressTask
}

export default function TaskStateText({task}: IProps) {
  function formatResult(): string {
    if (!task.processResult?.size || !task.storeResult?.size) return "未知"
    const compressedSize = task.storeResult?.size - task.processResult?.size
    const percent = ((compressedSize / task.storeResult?.size) * 100).toFixed(2)
    return `-${(compressedSize / 1000).toFixed(2)}K(${percent}%)`
  }
  const stateTextSet = {
    "0": <p className="text-orange-400 text-xs">等待中</p>,
    "1": <p className="text-purple-400 text-xs">上传中</p>,
    "2": <p className="text-blue-400 text-xs">压缩中</p>,
    "3": <p className="text-fuchsia-400 text-xs">下载中</p>,
    "4": <p className="text-green-400 text-xs">{formatResult()}</p>,
    "5": <p className="text-red-400 text-xs">错误</p>,
  }
  return stateTextSet[task.state]
}